package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.User;
import com.tanhua.model.vo.HuanXinUserVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Administrator
 */
@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String mobile) {
        LambdaQueryWrapper<User> qw=new LambdaQueryWrapper<>();
        qw.eq(User::getMobile, mobile);
        return userMapper.selectOne(qw);



    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public List<User> findAll() {
        return userMapper.selectList(Wrappers.emptyWrapper());
    }


    @Override
    public User findById(Long userId) {
        LambdaQueryWrapper<User> qw=new LambdaQueryWrapper<>();
        qw.eq(User::getId,userId);
        return userMapper.selectOne(qw);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findByHuanxin(String huanxinId) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("hx_user",huanxinId);
        return userMapper.selectOne(qw);
    }
}